package com.tencreat.common.config;

import cn.hutool.json.JSONObject;
import com.tencreat.common.core.domain.entity.SysDictData;
import com.tencreat.common.utils.DictUtils;
import lombok.Data;

import java.util.List;

/**
 * openIM 配置
 * https://docs.openim.io/zh-Hans/restapi/introduction
 */
@Data
public class OpenIMConfig {
    private String adminUserId;
    private String secret;
    private String url;
    private String avatarUser;
    private String avatarCustomer;

    public static OpenIMConfig getOpenIMConfig(){
        OpenIMConfig openIMConfig = new OpenIMConfig();
        List<SysDictData> config = DictUtils.getDictCache("openIM");
        for (SysDictData i : config) {
            if("adminUserId".equals(i.getDictLabel())){
                openIMConfig.adminUserId = i.getDictValue();
            }
            if("secret".equals(i.getDictLabel())){
                openIMConfig.secret = i.getDictValue();
            }
            if("url".equals(i.getDictLabel())){
                openIMConfig.url = i.getDictValue();
            }
            if("avatar_user".equals(i.getDictLabel())){
                openIMConfig.avatarUser = i.getDictValue();
            }
            if("avatar_customer".equals(i.getDictLabel())){
                openIMConfig.avatarCustomer = i.getDictValue();
            }
        }
        return openIMConfig;
    }
}
